The values assigned to the various data structures defined in a computer program are often intended to posses invariant properties. For example, a particular variable may be limited to a certain range of values. The invariant property of the variable is that l<=x<=u, where l is the lower bound of the range, u is the upper bound of the range, and x is the value of the variable. Another example is a variable that is constrained to be an aligned pointer to a 32-bit value, i.e. its low-order two bits must be zero.
During program execution, a data structure is updated one or more times with values that depend on the application logic and data input to the application. To protect against events during program execution that may result in data corruption or a fatal program error, application developers often program defensively to avoid these scenarios. For example, input data are checked for acceptable ranges.
While defensive programming catches many error conditions before they can cause serious problems, there may be some events that the developer has not considered. For example, an error in application logic may result in a data structure being assigned a value that is outside the invariant range. To create source code that checks every update to every data structure would unreasonably bloat the source code and make the source code difficult to read. Furthermore, while application developers are often aware of the invariant properties of data structures, compiler and program analysis tools cannot deduce these invariant properties. Thus, the task of guarding against violation of invariant properties is left to the developer.
A method an apparatus that address the aforementioned problems, as well as other related problems, are therefore desirable.